
$(function(){
    $("#UpArea").dialog({
        title:"修改",
        btnName:"修改",
        btnBind:function(){
            var params=$("#updateArea").serializeArray();
            var param="";
            for(var i in params){

                if(i==params.length-1){
                    param+=params[i].name+"="+params[i].value;
                }else{
                    param+=params[i].name+"="+params[i].value+"&";
                }
            }
            console.info(param)


            $.post("base/area/updateArea",param,function (msg) {
                $("#UpArea").dialog("close");
                $("#table").bootstrapTable("refresh");
                toastr.warning("信息提示",msg);
            },"text")
        }
    });

    $("#AddArea").dialog({
        title:"添加",
        btnName:"添加",
        btnBind:function(){
            var params=$("#adArea").serializeArray();
            var param="";
            for(var i in params){

                if(i==params.length-1){
                    param+=params[i].name+"="+params[i].value;
                }else{
                    param+=params[i].name+"="+params[i].value+"&";
                }
            }
            console.info(param)


            $.post("base/area/addArea",param,function (msg) {
                $("#AddArea").dialog("close");
                $("#table").bootstrapTable("refresh");
                toastr.warning("信息提示",msg);
            },"text")
        }
    });
});

function FormatState(val,row,index) {
    if(val=='Y'){
        return "是";
    }else{
        return "否";
    }
}


function FormatOperation(value,row,index){
    var peration = "<span class='btn btn-default' onclick='updateArea("+JSON.stringify(row)+")'><i class='glyphicon glyphicon-edit'></i>详情</span>&nbsp;<span class='btn btn-warning' onclick='deleteArea("+row.areaId+")'><i class='glyphicon glyphicon-remove'></i>删除</span>";
    return peration;
}

function addArea() {
    $(".modal .modal-body #AddArea").attr("class","show");
    $("#AddArea").dialog("open");
}

function  updateArea(row) {
    $("#updateArea").setForm(row);


    $("#updateArea input[name='branchCode']").val(row.branch.branchName);
    $("#updateArea input[name='warehouseCode']").val(row.warehouse.warehouseName);
    $("#updateArea input[name='departmentCode']").val(row.department.departmentName);



    $(".modal .modal-body #UpArea").attr("class","show");
    $("#UpArea").dialog("open");
    console.info(row);
}

function deleteArea(aid) {
    var param="aid="+aid;
    $.post("base/area/delArea",param,function (msg) {
        toastr.warning(msg);
        $("#table").bootstrapTable("refresh")
    },"text")
}
function searchTjArea() {
    var param=$("#condition").serializeArray();
    console.info(param)

    var obj={};
    for(var i in param){
        obj[param[i].name]=param[i].value;
    }
    $("#table").bootstrapTable("refresh",{query:obj});

}
function sss() {

    var a=$("#warehouseClass").val();
    if(a==1){
        $("select[name='departmentCode']").attr("disabled","disabled");
        $("select[name='warehouseCode']").removeAttr("disabled");
    }else if(a==2){
        $("select[name='departmentCode']").removeAttr("disabled");
        $("select[name='warehouseCode']").attr("disabled","disabled");
    }
}

function addAreaJb() {
    var a=$("#asdf").val();
    if(a==1){
        $("#adArea select[name='departmentCode']").attr("disabled","disabled");
        $("#adArea select[name='warehouseCode']").removeAttr("disabled");
    }else if(a==2){
        $("#adArea select[name='departmentCode']").removeAttr("disabled");
        $("#adArea select[name='warehouseCode']").attr("disabled","disabled");
    }
}